<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>中华爱情网</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
  <style type="text/css">
  body{font-family:"微软雅黑";padding:20px;border:0;}
	.form-div{font-size: 18px;line-height: 24px;line-height: 36px;}
  .title{color:#EE7E08;margin:0 6px;}
  </style>
</head>
<body>

<div  style="margin-bottom:20px;line-height:30px;font-size:20px;border-left:4px solid #28B6F6;color:#28B6F6;height:30px;text-align:center;">消费信息</div>
<img src="" id="img_dir" style="width:280px;margin-bottom:10px;"> 

<div class="form-div" style="margin-top:20px;">
  用户名：<span style="color:#EE7E08;" id="user_name"></span>
</div>
<div class="form-div">
店铺名：<span class="title" id="seller_name"></span>
</div>
<div class="form-div" style="margin-top:20px;">
  优惠券的主题：<div style="color:#EE7E08;" id="coupon_name"></div>
</div>
 <?php
 	$user_id = isset($result['userid'])?$result['userid']:12;
 	$user_name = isset($result['coupon']->user_name)?$result['coupon']->user_name:1;
 	$coupon_id = isset($result['coupon_id'])?$result['coupon_id']:1;
 	$coupon_name = isset($result['coupon']->coupon_name)?$result['coupon']->coupon_name:1;
 	$seller_name = isset($result['coupon']->seller_name)?$result['coupon']->seller_name:1;
 	$img_dir = isset($result['coupon']->img_dir)?$result['coupon']->img_dir:1;


 ?>
<script type="text/javascript">
	var img_dir = "<?=$img_dir?>";

	var user_name = "<?=$user_name?>";
	var user_id = "<?=$user_id?>";
	var coupon_id = "<?=$coupon_id?>";

	var coupon_name = "<?=$coupon_name?>";
	var seller_name = "<?=$seller_name?>";
	document.getElementById("img_dir").src = img_dir;
	document.getElementById("user_name").innerHTML = user_name;
	document.getElementById("coupon_name").innerHTML = coupon_name;
	document.getElementById("seller_name").innerHTML = seller_name;
	document.getElementById("img_dir").style.width= document.body.clientWidth*1-42+'px';
	
	var createAjax=function(){
	    var xhr=null;
	    try{//IE系列浏览器
	        xhr=new ActiveXObject("microsoft.xmlhttp");
	    }catch(e1){
	        try{//非IE浏览器
	            xhr=new XMLHttpRequest();
	        }catch(e2){
	            window.alert("您的浏览器不支持ajax，请更换！");
	        }
	    }
	    return xhr;
	};
	var ajax=function(conf){
	    var type=conf.type;//type参数,可选
	    var url=conf.url;//url参数，必填
	    var data=conf.data;//data参数可选，只有在post请求时需要
	    var dataType=conf.dataType;//datatype参数可选
	    var success=conf.success;//回调函数可选
	    if(type==null){//type参数可选，默认为get
	        type="get";
	    }
	    if(dataType==null){//dataType参数可选，默认为text
	        dataType="text";
	    }
	    var xhr=createAjax();
	    xhr.open(type,url,true);
	    if(type=="GET"||type=="get"){
	        xhr.send(null);
	    }else if(type=="POST"||type=="post"){
	        xhr.setRequestHeader("content-type","application/x-www-form-urlencoded");
	        xhr.send(data);
	    }
	    xhr.onreadystatechange=function(){
	        if(xhr.readyState==4&&xhr.status==200){
	            if(dataType=="text"||dataType=="TEXT"){
	                if(success!=null){//普通文本
	                    success(xhr.responseText);
	                }
	            }else if(dataType=="xml"||dataType=="XML"){
	                if(success!=null){//接收xml文档
	                    success(xhr.responseXML);
	                }
	            }else if(dataType=="json"||dataType=="JSON"){
	                if(success!=null){//将json字符串转换为js对象
	                    success(eval("("+xhr.responseText+")"));
	                }
	            }
	        }
	    };
	};

	ajax({
	    type:"POST",//post或者get，非必须
	    url:"/consumer/"+user_id+"/coupon/"+coupon_id+"/use?is_used=1",//必须的
	    dataType:"json",//text/xml/json，非必须
	    success:function(data){//回调函数，非必须
	    	if (data.error) {
	    		alert(data.message);
	    	}else{
	    		alert(data.message);
	    	}
	    }
	});		


</script>
</body>
</html>